// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database()

// 云函数入口函数
exports.main = async (event, context) => {
  console.log(event)
  switch (event.action) {
    case 'modifyCase': {
      return modifyCase(event)
    }
    default: {
      console.log('no function')
      return
    }
  }
}

async function modifyCase(event) {
  const cases = db.collection('cases')
  cases.doc(event._id).update({
    data: {
      doctorTreatment: event.doctorTreatment,
      state: event.state
    }
  })
}
